In [21]:
import os
import cv2
import glob
import random
import numpy as np
import matplotlib.pyplot as plt

X_path = ['X_train', 'X_val', 'X_test']
y_path = ['y_train', 'y_val', 'y_test']
In [23]:
for i in range(3):
    print(X_path[i], y_path[i])
    num_of_folders = len([x for x in os.listdir(X_path[i]) if x[0] != '.'])
    print(num_of_folders)
    for j in range(num_of_folders):
        sample_image = random.choice(glob.glob(os.path.join(X_path[i], str(j), '*.jpg')))
        pts = np.load(os.path.join(y_path[i], str(j) + '.npy'))[0]
        image = cv2.imread(sample_image)
        for k, p in enumerate(pts):
            cv2.circle(image, (p[0], p[1]), 2, (255 * (k % 3 == 0), 255 * (k % 2 == 0), 255), 2)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        plt.figure()
        plt.title(X_path[i] + ' #' + str(j))
        plt.imshow(image)
        plt.show()
X_train y_train
66
X_val y_val
5
X_test y_test
8